package com.matuw.android.util;

import android.app.Activity;
import android.app.Dialog;

import com.matuw.android.log.QLogger;


public class DialogUtils {

    public static void dismiss(Dialog dialog) {
        if (dialog == null || !dialog.isShowing()) {
            return;
        }

        Activity activity = ContextUtils.findActivity(dialog.getContext());
        if (activity == null) {
            try {
                // 可能是使用 Application context 弹出的
                dialog.dismiss();
            } catch (Exception e) {
                QLogger.e("dismiss", e);
            }
        } else if (ActivityUtils.isAvailable(activity)) {
            dialog.dismiss();
        }
    }
}
